<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>网站管理</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-row :gutter="6">
      <el-card>
        <el-col :span="2">
          <div>
            <el-statistic
              group-separator=","
              :precision="2"
              :value="number"
              title="总销量"
            ></el-statistic>
          </div>
        </el-col>
        <el-col :span="2">
          <div>
            <el-statistic
              group-separator=","
              :precision="2"
              :value="price"
              title="总销售额"
            ></el-statistic>
          </div>
        </el-col>
      </el-card>
    </el-row>
    <el-row :gutter="20">
      <el-col>
        <el-card>
            <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
            <div id="main" style="width: 750px;height:400px;"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
// 导入echarts
import * as echarts from 'echarts'
import _ from 'lodash'

export default {
    data() {
        return {
        //   options: {
        //     title: {
        //     text: '用户来源'
        //     },
        //     tooltip: {
        //     trigger: 'axis',
        //     axisPointer: {
        //         type: 'cross',
        //         label: {
        //         backgroundColor: '#E9EEF3'
        //         }
        //     }
        //     },
        //     grid: {
        //     left: '3%',
        //     right: '4%',
        //     bottom: '3%',
        //     containLabel: true
        //     },
        //     xAxis: [
        //     {
        //         boundaryGap: false
        //     }
        //     ],
        //     yAxis: [
        //     {
        //         type: 'value'
        //     }
        //     ]
        // }
        option: {
            xAxis: {
              data: []
            },
            yAxis: {},
            series: [
              {
                type: 'bar',
                name: '销量',
                data: []
              },
              {
                type: 'bar',
                name: '销售额',
                data: []
              }
            ]
          },
          number: 0.00,
          price: 0
        }
    },
    created() {

    },
    // 此时页面上的元素，已经被渲染完毕了
    async mounted() {
      // 基于准备好的dom，初始化echarts实例
      const myChart = echarts.init(document.getElementById('main'))
      // 准备数据和配置项
      const { data: res } = await this.$axios.get('/order/echart')
      if (res.code !== 200) {
        return this.$message.error('获取数据报表失败! ')
      }
      const rsult = _.merge(res.data.options, this.option)
      console.log(rsult)
      // 展示数据
      myChart.setOption(rsult)

      const { data: result } = await this.$axios.get('/order/numberAndPrice')
      if (result.code !== 200) {
        return this.$message.error('获取数据失败! ')
      }
      this.number = result.data.number
      this.price = result.data.price
    },
    methods: {

    }
}
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 10px;
}
.like {
    cursor: pointer;
    font-size: 25px;
    display: inline-block;
}
</style>
